<?php
/**
 * 消息模板
 * Created by PhpStorm.
 * User:
 * Date: 2017/4/26
 * Time: 15:07
 */

namespace App\Services;


use Illuminate\Support\Facades\Config;

trait FeeServices
{
    use BaseServices;
    /**
     * 下发收费规则
     *
     * @param $data  [park_code,start_time,end_time,msgno,msg,mode]
     * @return json
     */
    public function send($arr)
    {
        $data = $this->getJson($arr);
        $res = curl_post_json(config('custom.fee_send_api_url'),$data);
        return $this->reData($res);
    }

    function  getJson($arr){
        $key = $arr['rule']!=8?"default":"auth";
        if($arr['car_type'] == 0){
            return  '{"park_code":'.$arr['park_code'].',
            "depot_id": 0,
            "auth_type":'.$arr['rule'].',
            "auth_free_flag":'.$arr['is_free'].',
            "'.$key.'":
            {
              "cycle_info":
                {
                "cycle_value": '.$arr['period_top'].'
                },
                "car":
                {
                  "one_day": {
                      "free_time": '.$arr['free_time'].',
                      "top_limit": '.$arr['period_top'].'
                  },
                  "daylight": {
                      "linear": 1,
                      "common":{
                      "top_limit": '.$arr['period_top'].',
                          "first_min":'.$arr['start_time'].',
                          "first_value": '.$arr['start_money'].',
                          "after_min":  '.$arr['adders_time'].',
                          "after_value": '.$arr['adders_money'].'
                      }
                  },
                  "night": {
                      "linear": 1,
                      "common":{
                      "top_limit": '.$arr['period_top'].',
                          "first_min": '.$arr['start_time'].',
                          "first_value": '.$arr['start_money'].',
                          "night_min":   '.$arr['adders_time'].',
                          "night_value": '.$arr['adders_money'].'
                      }
                  }
              }
            }
        }';
        } else {
            return  '{"park_code":'.$arr['park_code'].',
            "depot_id": 0,
            "auth_type":'.$arr['rule'].',
            "auth_free_flag":'.$arr['is_free'].',
            "'.$key.'":
            {
              "cycle_info":
                {
                "cycle_value": '.$arr['period_top'].'
                },
                "van":
                {
                  "one_day": {
                      "free_time": '.$arr['free_time'].',
                      "top_limit": '.$arr['period_top'].'
                  },
                  "daylight": {
                      "linear": 1,
                      "common":{
                          "top_limit": '.$arr['period_top'].',
                          "first_min": '.$arr['start_time'].',
                          "first_value": '.$arr['start_money'].',
                          "after_min":  '.$arr['adders_time'].',
                          "after_value": '.$arr['adders_money'].'
                      }
                  },
                  "night": {
                      "linear": 1,
                      "common":{
                          "top_limit": '.$arr['period_top'].',
                          "first_min": '.$arr['start_time'].',
                          "first_value": '.$arr['start_money'].',
                          "night_min":   '.$arr['adders_time'].',
                          "night_value": '.$arr['adders_money'].'
                      }
                  }
              }
            }
        }';
        }
        return $data;
    }

}